Skip to content

Conversation

@dignifiedquire
Copy link
Contributor

@dignifiedquire dignifiedquire commented Oct 10, 2025

Description

Closes #3470

Breaking Changes

  • removed
    • iroh::endpoint::Builder::n0_discovery
    • iroh::endpoint::Builder::discovery_dht
    • iroh::endpoint::Builder::discovery_local_network
    • iroh::endpoint::Builder::discovery
    • iroh::discovery::DiscoveryContext
    • iroh::endpoint::Builder::default
  • added
    • iroh::Endpoint::bind - this allows to immediately create an Endpoint with the defaults and binds it
    • iroh::endpoint::Endpoint::empty_builder
    • iroh::endpoint::presets - new module, defining a trait on how to preconfigure and Endpoint
    • iroh::endpoint::Builder::new - creates a new builder with the N0 preset
    • iroh::endpoint::Builder::preset
    • iroh::endpoint::Builder::empty - creates a new builder, completely empty (no discovery, no relay map)
  • changed
    • iroh::'Endpoint::add_discovery is now called just discovery
    • iroh::discovery::IntoDiscovery now takes an Endpoint instead of a DiscoveryContext

@dignifiedquire dignifiedquire self-assigned this Oct 10, 2025
@dignifiedquire dignifiedquire added this to the v0.94 milestone Oct 10, 2025
@github-actions
Copy link

github-actions bot commented Oct 10, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/3523/docs/iroh/

Last updated: 2025-10-17T08:25:55Z

@github-actions
Copy link

github-actions bot commented Oct 10, 2025

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 1842948

@n0bot n0bot bot added this to iroh Oct 10, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Oct 10, 2025
/// Defines a preset
pub trait Preset {
/// Applies the configuration to the passed in [`Builder`].
fn apply(self, builder: Builder) -> Builder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for preset to take self and not &self?

Imagine you had a complex preset, you would have to clone it to apply it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing specific, I was just expecting them to be use once only

@dignifiedquire dignifiedquire marked this pull request as ready for review October 14, 2025 08:54
@dignifiedquire dignifiedquire force-pushed the feat-presets branch 2 times, most recently from 9cbb73b to bc79613 Compare October 14, 2025 08:57
@dignifiedquire dignifiedquire force-pushed the feat-presets branch 7 times, most recently from 30b8edd to 2dc47ed Compare October 15, 2025 13:59
@ramfox
Copy link
Member

ramfox commented Oct 17, 2025

Hey, so I pushed a commit that includes removing .relay_mode(RelayMode::Disabled) where we are now using an empty_builder(), since that already includes RelayMode::Disabled and added using an empty_builder in places that shouldn't have discovery enabled in the test (from what I can tell).

If I've misunderstood the purpose of a test feel free to revert or change.

@ramfox
Copy link
Member

ramfox commented Oct 17, 2025

Two concerns about this PR:

  1. users are not going to be used to having discovery on by default
  2. it's not immediately obvious that if you use an empty_builder and then add discovery services yourself, you may be foot-gunning yourself if you don't also add a specific relay mode to the endpoint builder as well, since most of our discovery really depends on being connected to a relay mode, and empty_builder sets the relay mode to RelayMode::Disabled

The first issue is just about communicate, and I think folks will just get used to it.

The second one I'm more concerned about because it's easy to just not realize what you are doing. This may also be solved a bit by documentation (for example, in the empty_builder method, mentioning that if you plan to add a discovery service you may also want to add a relay mode to the builder before binding.)

I think we need a bit of an answer around the second point before we can merge. We can decide it's enough to just communicate this through docs, or we can decide that's too big of a foot-gun and need to change some things, or we can decide it doesn't actually matter, or some other fourth option.

One general thought:

  • for clarity, we may want to make some presets in our test utils, that makes it obvious what the expectations are for the test, even if the preset is really just equivalent to Endpoint::empty_builder() & feels redundant.
    This may help if we:
    a) change what the defaults are in APIs like empty_builder or Endpoint::bind & then need to search each test and make sure we update accordingly
    b) just make it really clear when setting up the test, what the expectations are for endpoint at a glance.

Just a thought!

@dignifiedquire
Copy link
Contributor Author

@ramfox I have pushed a version that enforces choosing a RelayMode when constructing an empty builder, in many use cases this is the same or less code than before, and only in the full empty version a little bit more verbose, which seems fine given the better understanding this lends to the reader and writer of the code

@dignifiedquire dignifiedquire added this pull request to the merge queue Oct 18, 2025
Merged via the queue into main with commit 2d367f9 Oct 18, 2025
28 of 29 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

replace iroh::endpoint::Builder::discovery_n0 with a more declarative API

5 participants